package cn.itcast.mq.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class SpringRabbitListener {

  /*  @RabbitListener(queues = "xxxx")
    public void listenSimpleQueue(String msg) {
        System.out.println("消费者接收到xxxx的消息：【" + msg + "】");
        // 模拟异常
        int i = 1 / 0;
    }*/

    @RabbitListener(queues = "simple.queue")
    public void SimpleQueue(String msg) {
        System.out.println("消费者接收到simple.queue的消息：【" + msg + "】");
        // 模拟异常
        int i = 1 / 0;
    }

    //利用死信队列来实现消息的延迟发送
//    @RabbitListener(bindings = @QueueBinding(
//            exchange = @Exchange(name = "dl.direct", type = "direct"),
//            value = @Queue(name = "dl.queue"),
//            key = "dl"
//    ))
//    public void ttlQueue(String msg) {
//        System.out.println("我收到延迟消息:" +msg);
//    }
}
